const Router = require('koa-router')

const CartRouter = new Router({ prefix: '/carts' })

const { auth } = require('../middleware/auth.middleware')

const { paramValidator } = require('../middleware/cart.middleware')

const { verifyGoods } = require('../middleware/goods.middleware')

const { add, findAll, update, remove, selectAll, unSelectAll, total } = require('../controllers/cart.controllers')
// 添加购物车
CartRouter.post('/', auth, paramValidator({ goods_id: 'number' }), verifyGoods, add)
// 获取购物车列表
CartRouter.get('/', auth, findAll)
// 更新购物车
CartRouter.patch('/:id', auth, paramValidator({
    number: {
        type: "number", require: false
    },
    selected: {
        type: "bool", require: false
    }
}), update)

// 删除购物车
CartRouter.delete('/', auth, paramValidator({ ids: 'array' }), remove)
// 全选
CartRouter.post('/selectAll', auth, selectAll)
CartRouter.post('/unSelectAll', auth, unSelectAll)
// 总数
CartRouter.get('/total', auth, total)
module.exports = CartRouter